package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.SemesterScoreMapper;
import com.chzu.pojo.SemesterScore;
import com.chzu.pojo.SysUser;
import com.chzu.pojo.vo.ScoreChartDateVo;
import com.chzu.pojo.vo.SemesterAndReadScoreVo;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.SemesterScoreService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName SemesterScoreServiceImpl
 * @Description TODO
 * @Date 2022/02/10 21:11
 */
@Service
public class SemesterScoreServiceImpl extends ServiceImpl<SemesterScoreMapper, SemesterScore> implements SemesterScoreService {

    @Resource
    private SemesterScoreMapper semesterScoreMapper;

    /**
     *  获取用户每学期的绩点分数
     * @return 集合
     */
    @Override
    public List<SemesterScore> getSemesterScore() {
        SysUser user = (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String openId = user.getOpenId();
        return semesterScoreMapper.getSemesterScore(openId);
    }

    /**
     * 分页查询每个学期所有学生的
     * @param queryInfo 分页对象
     * @param semester 学期
     * @return
     */
    @Override
    public JsonResult<Object> getAllSemesterScore(QueryInfo queryInfo, String semester) {
        PageHelper.startPage(queryInfo.getPageNumber(),queryInfo.getPageSize());
        Page<SemesterAndReadScoreVo> page = semesterScoreMapper.getAllSemesterScore(queryInfo.getQueryString(), semester);
        long total = page.getTotal();
        List<SemesterAndReadScoreVo> result = page.getResult();
        return PageResult.pageResult(result,total);
    }


    /**
     * 获得各个绩点分段的人数
     * @return
     */
    @Override
    public List<ScoreChartDateVo> getStudentNumByAverageScore() {
        return semesterScoreMapper.getStudentNumByAverageScore();
    }

    /**
     * 获取所有学期信息
     * @return
     */
    @Override
    public List<SemesterScore> getAllSemester() {
        return semesterScoreMapper.getAllSemester();
    }
}
